package com.starry.module.system.core.tenant.mapper;

import com.starry.core.common.domain.vo.PageVo;
import com.starry.db.core.mapper.BaseMapperX;
import com.starry.db.core.query.LambdaQueryWrapperX;
import com.starry.module.system.api.tenant.domain.qo.SysTenantPageQo;
import com.starry.module.system.core.tenant.entity.SysTenant;
import org.apache.ibatis.annotations.Mapper;

/**
 * 系统租户-数据库服务层
 *
 * @author xiaoke
 */
@Mapper
public interface SysTenantMapper extends BaseMapperX<SysTenant> {

    /**
     * 分页查询
     *
     * @param pageQo 分页参数
     * @return PageVo<SysTenant>
     */
    default PageVo<SysTenant> selectPage(SysTenantPageQo pageQo) {
        return selectPage(pageQo, new LambdaQueryWrapperX<SysTenant>()
                .likeIfPresent(SysTenant::getName, pageQo.getName())
                .eqIfPresent(SysTenant::getStatus, pageQo.getStatus())
                .orderByDesc(SysTenant::getCreateTime)
        );
    }

    default SysTenant selectByWebsite(String website) {
        return selectOne(new LambdaQueryWrapperX<SysTenant>()
                .eq(SysTenant::getWebsite, website)
        );
    }
}

